<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\web\UploadedFile;
/**
 * This is the model class for table "seven_node".
 *
 * @property integer $node_id
 * @property string $node_name
 * @property string $node_controller
 * @property string $node_method
 * @property string $node_pid
 * @property integer $node_status
 */
class NodeModel extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public $file='';
    public static function tableName()
    {
        return 'seven_node';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['node_name'], 'required'],
            [['node_pid', 'node_status'], 'integer'],
            [['node_name', 'node_controller', 'node_method'], 'string', 'max' => 30],
            [['file'],'file'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'node_id' => 'Node ID',
            'node_name' => 'Node Name',
            'node_controller' => 'Node Controller',
            'node_method' => 'Node Method',
            'node_pid' => 'Node Pid',
            'node_status' => 'Node Status',
        ];
    }
    public  function getNodeOrder($data,$pid=0,$lavel=0)
    {
        $tmp = array();
        foreach ($data as $key => $val) {
            if($val['node_pid'] == $pid)
            {
                $val['lavel']=$lavel;
                $tmp[] = $val;
                $tmp = array_merge($tmp,$this->getNodeOrder($data,$val['node_id'],$lavel+1));
            }
        }
        return $tmp;
    }
}
